package cn.dnuihyy406.dnuifood_16110100406.controller.mefragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.telecom.Call;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import cn.dnuihyy406.dnuifood_16110100406.R;
import cn.dnuihyy406.dnuifood_16110100406.bean.GetCommentBean;
import cn.dnuihyy406.dnuifood_16110100406.listener.OnRetrofitListener;

public class MyOrderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>  {
    private Context mContext;
    private List<GetCommentBean>getCommentBeanList1;
    private LayoutInflater mLayoutInflater;
    //    SharedPreferences sharedPreferences;
//    String user_id;
    public MyOrderAdapter(Context mContext,List getCommentBeanList1){
        this.mContext=mContext;
        this.getCommentBeanList1=getCommentBeanList1;
        mLayoutInflater=LayoutInflater.from(mContext);
    }
    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View v=mLayoutInflater.from(viewGroup.getContext()).inflate(R.layout.order_item,viewGroup,false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder Holder, final int i) {
//        sharedPreferences = mContext.getSharedPreferences("jzd", Context.MODE_PRIVATE);
//        user_id = sharedPreferences.getString("userid","");
        final GetCommentBean x=getCommentBeanList1.get(i);
        if (null==x){
            return;
        }
        ViewHolder viewHolder=(ViewHolder)Holder;
        viewHolder.o_ordertime.setText(x.getOrder_time());
        viewHolder.o_shopname.setText(x.getShopname());
        viewHolder.o_foodname.setText(x.getFoodname());
        viewHolder.o_price.setText(x.getPrice());
        viewHolder.o_commentit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(mContext,CommentActivity.class);
                String str = String.valueOf(getCommentBeanList1.get(i).getItem_id());
                intent.putExtra("itemid",str);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return getCommentBeanList1.size();
    }




    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView o_foodname,o_price,o_shopname,o_ordertime;
        Button o_commentit;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            o_foodname = itemView.findViewById(R.id.o_foodname);
            o_shopname = itemView.findViewById(R.id.o_shopname);
            o_price = itemView.findViewById(R.id.o_price);
            o_ordertime=itemView.findViewById(R.id.o_ordertime);
            o_commentit=itemView.findViewById(R.id.o_commentit);
        }
    }
}